<?php

namespace app\admin\model;

use think\Model;


class Company extends Model
{
    // 表名
    protected $name = 'company';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public static function dataList($params = [], $sort, $order, $offset, $limit)
    {
        $where = [];
        if (isset($params['company_name']) && $params['company_name']) {
            $where['c.company_name'] = ['like', $params['company_name'].'%'];
        }
        if (isset($params['company_lianxiren']) && $params['company_lianxiren']) {
            $where['c.company_lianxiren'] = ['like', $params['company_lianxiren'].'%'];
        }
        if (isset($params['deliver_uname']) && $params['deliver_uname']) {
            $where['u.hua_name'] = ['like', $params['deliver_uname'].'%'];
        }
        if (isset($params['requesting']) && $params['requesting']) {
            if ($params['requesting'] == 2) {
                $where['c.requesting'] = 2;
            } else {
                $where['c.requesting'] = ['neq', 2];
            }
        }
        $list = db('company')->alias('c')->join('user u', 'u.id = c.user_id')->field('c.*,u.hua_name,u.money')->where($where)->order($sort, $order)->limit($offset, $limit)->select();
        return $list;
    }

    public static function dataCount($params = [])
    {
        $where = [];
        if (isset($params['company_name']) && $params['company_name']) {
            $where['company_name'] = ['like', $params['company_name'].'%'];
        }
        if (isset($params['company_lianxiren']) && $params['company_lianxiren']) {
            $where['company_lianxiren'] = ['like', $params['company_lianxiren'].'%'];
        }
        if (isset($params['deliver_uname']) && $params['deliver_uname']) {
            $where['u.hua_name'] = ['like', $params['deliver_uname'].'%'];
        }
        if (isset($params['requesting']) && $params['requesting']) {
            if ($params['requesting'] == 2) {
                $where['c.requesting'] = 2;
            } else {
                $where['c.requesting'] = ['neq', 2];
            }
        }
        $count = db('company')->alias('c')->join('user u', 'u.id = c.user_id')->count();
        return $count;
    }
}
